Skip to content

Comments

OpenTelemetry MCP client spans#2132

Draft
aabmass wants to merge 5 commits intomodelcontextprotocol:mainfrom
aabmass:otel-client-spans
Draft

OpenTelemetry MCP client spans#2132
aabmass wants to merge 5 commits intomodelcontextprotocol:mainfrom
aabmass:otel-client-spans

Conversation

@aabmass
Copy link
Contributor

@aabmass aabmass commented Feb 24, 2026

Part of #421

Depends on

Motivation and Context

Implements the minimal client side tracing portion as specified in https://github.com/open-telemetry/semantic-conventions/blob/v1.40.0/docs/gen-ai/mcp.md#client

  • This only includes the "required" attributes for now.
  • I threaded a new TracerProvider optional parameter into the MCP client and server sessions for DI purposes. That way users and test code can isolate the span creation.
  • This also covers calls from server -> client like sampling and notifications.

How Has This Been Tested?

Added lots of new test cases showing spans and their parent child relationships.

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

See if tests still fail
This fix covers in memory, streamable http, and sse transports.
This works for both incoming client->server requests and server->client requests like MCP Sampling.
finish client spans

Inject tracer_provider into servers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant